package com.g02.qt;

public class ReverseNode {
    static ListNode haveHead(ListNode head) {
        // 带头节点的版本
        ListNode newHead = new ListNode(-1);
        ListNode p1 = head;
        while(p1 != null) {
            ListNode temp = p1.next;
            p1.next = newHead.next;
            newHead.next = p1;
            p1 = temp;
        }
        return newHead.next;
    }

    static ListNode noHead(ListNode head) {
        // 不用头节点的版本
        ListNode prev = null;
        ListNode cur = head;
        while (cur != null) {
            ListNode next = cur.next;
            cur.next = prev;
            prev = cur;
            cur = next;
        }
        return prev;
    }
}
